
        $('#cover').blur(function(){
            if(this.value == ""){
               $('#imgPreview').attr('src', this.value).parent().hide();
                return ;
            }
            $('#imgPreview').attr('src', this.value).parent().show();
        });

        $('#slide').blur(function(){
            if(this.value == ""){
                $('#slideList').html("").hide();
                return;
            }
            let picList = this.value.split('|');
            let str = '';
            const itemList = {};
            $('#slideList li').each(function(index, dom){
                let img = $(dom).find("img").attr('src');
                itemList[img] = dom.outerHTML;
            });
            for(const pic of picList){
                if(itemList.hasOwnProperty(pic)){
                   str += itemList[pic];
                }else{
                    str += '<li><img src="'+ pic +'" onclick="window.open(this.src)"/><input type="text" placeholder="图片备注" name="slide_remark[]" value=""></li>';
                }
            }
            $('#slideList').html(str).show();
        });


        //手动上传封面图片
        upload.render({
            elem: '#btnChoose'
            , url: '{{url('admin/uploads/upload')}}'
            , auto: false
            , data: {folder: 'banner'}
            //,multiple: true
            , bindAction: '#btnUpload'
            , choose: function (obj) {
                var that = this;
                obj.preview(function (index, file,result) {
                    $('#boxImgPreview').html("<img src='"+ result+"' style='max-width:150px;max-height:150px;' />").show();
                    obj.resetFile(index, file, encodeURI(file.name));
                    $('#btnUpload').show();
                });
            }
            , before: function () {
                layer.msg( '上传中' , { icon: 16 , time: 1000 } );
            }
            , done: function (res,index) {
                console.log(res)
                $('#imgPreview').attr('src', res.data.src).parent().show();
                $('#cover').val(res.data.src);
                layer.msg( '上传成功',{icon:1, time:1000} );
                 // 删除数组中上传成功的文件，防止重复上传  重点*****
                delete this.files[index];
            }
        });

        //轮播图
        $('#slideList .exist_file').on('click', function () {
            var id = $(this).attr('data-id');
            var slide = $('#slide').val();
            if (slide != '') {
                var slideArray = slide.split('|');
                var index = slideArray.indexOf(id);
                if (index > -1) {
                    var tmp = slideArray.splice(index, 1);
                    $('#slide').val(tmp.join('|'));
                }
            }
            $(this).parent().remove();
        });

        //附件信息
        $('#attachmentList .exist_attach').on('click', function () {
            var id = $(this).attr('data-id');
            var attachment = $('#attachment').val();
            if (attachment != '') {
                var attachmentArray = attachment.split(',');
                var index = attachmentArray.indexOf(id);
                if (index > -1) {
                    //var tmp = attachmentArray.splice(index, 1);
                    $('#attachment').val(attachmentArray.join(','));
                }
            }
            $(this).parent().parent().remove();
        });

        var attachmentListView = $('#attachmentList');
        var attachmentUploadListIns = upload.render({
            elem: '#btnAttachment'
            , url: '{{url('admin/uploads/upload')}}'
            , data: {folder: 'attachment'}
            , accept: 'file'
            , multiple: true
            , number: 3
            , auto: false
            , bindAction: '#btnAttachmentAction'
            , choose: function (obj) {
                $('#attachmentTable').show();
                $('#btnAttachmentAction').show();
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列

                //读取本地文件
                obj.preview(function (index, file, result) {
                    var tr = $(['<tr id="attachment-upload-' + index + '">'
                        , '<td>' + file.name + '</td>'
                        , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                        , '<td><div class="layui-progress" lay-filter="progress-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                        , '<td>'
                        , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                        , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        , '</td>'
                        , '</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function () {
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function () {
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        attachmentUploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    attachmentListView.append(tr);

                    element.render('progress');
                });
            }
            , done: function (res, index, upload) {
                if (res.code == 200) { //上传成功
                    var fileList = $('#attachment').val();
                    if (fileList != '') {
                        fileList += ',';
                    }
                    fileList += res.data.id;
                    $('#attachment').val(fileList);
                    var tr = attachmentListView.find('tr#attachment-upload-' + index)
                        , tds = tr.children();
                    tds.eq(3).html(''); //清空操作
                    delete this.files[index]; //删除文件队列已经上传成功的文件
                    return;
                }
                this.error(index, upload);
            }
            , allDone: function (obj) {
                console.log(obj)
            }
            , error: function (index, upload) {
                var tr = attachmentListView.find('tr#attachment-upload-' + index)
                    , tds = tr.children();
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
            , progress: function (n, elem, e, index) {
                console.log(n);
                element.progress('progress-' + index, n + '%'); //进度条
            }
        });

        var slideListView = $('#slideList');
        var slideUploadListIns = upload.render({
            elem: '#btnSlide'
            , url: '{{url('admin/uploads/upload')}}'
            , data: {folder: 'slide'}
            , accept: 'file'
            , multiple: true
            , number: 3
            , auto: false
            , bindAction: '#btnSlideAction'
            , choose: function (obj) {
                $('#slideTable').show();
                $('#btnSlideAction').show();
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列

                //读取本地文件
                obj.preview(function (index, file, result) {
                    var tr = $(['<li id="slide-upload-' + index + '">'
                        , '<a class="img_close demo-delete" href="javascript:;">x</a>'
                        , '<img src="' + result + '" alt="' + file.name + '" >'
                        , '<div class="layui-progress progressPos" lay-filter="progress-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div>'
                        , '<div class="operate">'
                        , '<button class="layui-btn layui-btn-xs demo-reload layui-hide" style="background: #f60;">重传</button>'
                        , '</div>'
                        ,'<input type="text" name="slide_remark[]" value="">'
                        , '</li>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function () {
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function () {
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        slideUploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    slideListView.append(tr);

                    element.render('progress');
                });
            }
            , done: function (res, index, upload) {
                if (res.code == 200) { //上传成功
                    var fileList = $('#slide').val();
                    if (fileList != '') {
                        fileList += '|';
                    }
                    fileList += res.data.src;
                    $('#slide').val(fileList);
                    var tr = slideListView.find('li#slide-upload-' + index)
                        , tds = tr.children();
                    tds.eq(3).html(''); //清空操作
                    delete this.files[index]; //删除文件队列已经上传成功的文件
                    return;
                }
                this.error(index, upload);
            }
            , allDone: function (obj) {
                console.log(obj)
            }
            , error: function (index, upload) {
                var tr = slideListView.find('li#slide-upload-' + index)
                    , tds = tr.children();
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
            , progress: function (n, elem, e, index) {
                console.log(n);
                element.progress('progress-' + index, n + '%'); //进度条
            }
        });